// pages/me/userinfor/userinfor.js
var app = getApp(); 

Page({

  /**
   * 页面的初始数据
   */
  data: {
    picture: "../../../image/0414couser.png",
    name: "",

    //user information
    username:"",
    pid:"",
    phone:"",
    email:"",
    loginname:"",
    hospitalname:"",
    categoryname:"",
    levelname:"",
    description:"",
    showdocinfor:false
  },

  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {

    var that = this;

    var utype = wx.getStorageSync("UserType");
    if (utype == '0') {
      wx.redirectTo({
        url: '/pages/me/myinfor/myinfor'
      })

      return;
    }

    this.setData({
      name: app.globalData.userInfo.nickName,
      picture: app.globalData.userInfo.avatarUrl
    })
    
    var atkey = wx.getStorageSync("AccessToken");

    wx.showLoading({
      title: '数据加载中...'
    })

    // --------- 发送凭证 ------------------
    wx.request({
      url: app.globalData.getUserInfor,
      data: { AccessToken: atkey, UserType: utype },
      header: {
        'content-type': 'application/json'
      },

      success: function (res) {

        that.setData({
          username: res.data.datum.NAME,
          pid: res.data.datum.PID,
          phone: res.data.datum.PHONE,
          email: res.data.datum.EMAIL,
          loginname: res.data.datum.USERNAME,
          hospitalname: res.data.datum.HOSPITALNAME,
          categoryname: res.data.datum.CATEGORYNAME,
          levelname:res.data.datum.LEVELNAME,
          description: res.data.datum.DESCRIPTION,
          showdocinfor: res.data.datum.ISDOCTOR
        });

      
        wx.hideLoading();

      },
      fail:function(){
        util.showRejectToast('数据加载失败！');
      }
    })



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    app.userlogin();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})